<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
  <head>
    <title>KRPC::Services</title>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
    <link href='../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
    <script type='text/javascript'>
      //<![CDATA[
        function popupCode(url) {
          window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
        }
        
        function toggleCode(id) {
          var code = document.getElementById(id)
        
          code.style.display = code.style.display != 'block' ? 'block' : 'none'
          return true
        }
        
        // Make codeblocks hidden by default
        document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
      //]]>
    </script>
  </head>
  <body class='page'>
    <div class='class' id='wrapper'>
      <div class='header'>
        <h1 class='name'>
          <span class='type'>module</span>
          KRPC::Services
        </h1>
        <ol class='paths'>
          <li>
            <a target="docwin" href="../../files/lib/krpc/service_rb.html">lib/krpc/service.rb</a>
          </li>
        </ol>
      </div>
      <div id='content'>
        <div id='text'>
          <div id='description'></div>
          <div id='method-list'>
            <h2>Methods</h2>
            <h3>Public Class</h3>
            <ol>
              <li><a target="docwin" href="#method-c-create_service">create_service</a></li>
            </ol>
          </div>
          <div id='context'>
          </div>
          <div id='class-list'>
            <h2>Classes and Modules</h2>
            <ol>
              <li><a target="docwin" href="Services/KRPC.html">KRPC::Services::KRPC</a></li>
              <li><a target="docwin" href="Services/ServiceBase.html">KRPC::Services::ServiceBase</a></li>
            </ol>
          </div>
          <div id='section'>
            <div id='methods'>
              <h2>Public Class methods</h2>
              <div class='method public-class' id='method-method-c-create_service'>
                <a name='method-c-create_service'></a>
                <div class='synopsis'>
                  <span class='name'>create_service</span>
                  <span class='arguments'>(service_msg)</span>
                </div>
                <div class='description'>
                  
                  <p>Generate classes and methods for the service - see documentation for <a
                  href="Client.html#method-i-generate_services_api-21">KRPC::Client#generate_services_api!</a></p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-c-create_service-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-c-create_service-source'><span class="ruby-comment"># File lib/krpc/service.rb, line 11</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_service</span>(<span class="ruby-identifier">service_msg</span>)&#x000A;  <span class="ruby-identifier">service_name</span> = <span class="ruby-identifier">service_msg</span>.<span class="ruby-identifier">name</span>&#x000A;  &#x000A;  <span class="ruby-comment"># Create service class</span>&#x000A;  <span class="ruby-identifier">service_class</span> = <span class="ruby-constant">Class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">ServiceBase</span>)&#x000A;  <span class="ruby-identifier">const_set</span>(<span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">service_class</span>)&#x000A;  &#x000A;  <span class="ruby-comment"># Create service&#39; classes</span>&#x000A;  <span class="ruby-identifier">service_msg</span>.<span class="ruby-identifier">classes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:name</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">sc_name</span><span class="ruby-operator">|</span>&#x000A;    <span class="ruby-constant">TypeStore</span>[<span class="ruby-node">&quot;Class(#{service_name}.#{sc_name})&quot;</span>]&#x000A;  <span class="ruby-keyword">end</span>&#x000A;  &#x000A;  <span class="ruby-comment"># Create service&#39; enums</span>&#x000A;  <span class="ruby-identifier">service_msg</span>.<span class="ruby-identifier">enumerations</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">enum</span><span class="ruby-operator">|</span>&#x000A;    <span class="ruby-identifier">enum_type</span> = <span class="ruby-constant">TypeStore</span>[<span class="ruby-node">&quot;Enum(#{service_name}.#{enum.name})&quot;</span>]&#x000A;    <span class="ruby-identifier">enum_type</span>.<span class="ruby-identifier">set_values</span>(<span class="ruby-identifier">enum</span>.<span class="ruby-identifier">values</span>)&#x000A;  <span class="ruby-keyword">end</span>&#x000A;  &#x000A;  <span class="ruby-comment"># Create service&#39; procedures</span>&#x000A;  <span class="ruby-identifier">service_msg</span>.<span class="ruby-identifier">procedures</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">proc</span><span class="ruby-operator">|</span>&#x000A;    <span class="ruby-keyword">if</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_class_method_or_property_accessor</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;      <span class="ruby-identifier">class_name</span>  = <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">get_class_name</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;      <span class="ruby-identifier">class_cls</span> = <span class="ruby-constant">TypeStore</span>[<span class="ruby-node">&quot;Class(#{service_name}.#{class_name})&quot;</span>].<span class="ruby-identifier">ruby_type</span>&#x000A;      <span class="ruby-identifier">method_name</span> = <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">get_class_method_or_property_name</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;      <span class="ruby-keyword">if</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_class_property_accessor</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)  <span class="ruby-comment"># service&#39; class property</span>&#x000A;        <span class="ruby-keyword">if</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_class_property_getter</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;          <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">class_cls</span>, <span class="ruby-identifier">method_name</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>, <span class="ruby-value">:prepend_self_to_args</span>)&#x000A;        <span class="ruby-keyword">else</span>&#x000A;          <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">class_cls</span>, <span class="ruby-identifier">method_name</span> <span class="ruby-operator">+</span> <span class="ruby-string">&#39;=&#39;</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>, <span class="ruby-value">:prepend_self_to_args</span>, <span class="ruby-value">:no_stream</span>)&#x000A;        <span class="ruby-keyword">end</span>&#x000A;      <span class="ruby-keyword">elsif</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_class_method</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)  <span class="ruby-comment"># service&#39; class method</span>&#x000A;        <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">class_cls</span>, <span class="ruby-identifier">method_name</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>, <span class="ruby-value">:prepend_self_to_args</span>)&#x000A;      <span class="ruby-keyword">else</span>  <span class="ruby-comment"># service&#39; static class method</span>&#x000A;        <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">class_cls</span>, <span class="ruby-identifier">method_name</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>, <span class="ruby-value">:static</span>)&#x000A;      <span class="ruby-keyword">end</span>&#x000A;    <span class="ruby-keyword">elsif</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_property_accessor</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)  <span class="ruby-comment"># service&#39; property</span>&#x000A;      <span class="ruby-identifier">property_name</span> = <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">get_property_name</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;      <span class="ruby-keyword">if</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_property_getter</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;        <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">service_class</span>, <span class="ruby-identifier">property_name</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>)&#x000A;      <span class="ruby-keyword">elsif</span> <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">is_a_property_setter</span>(<span class="ruby-identifier">proc</span>.<span class="ruby-identifier">attributes</span>)&#x000A;        <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">service_class</span>, <span class="ruby-identifier">property_name</span> <span class="ruby-operator">+</span> <span class="ruby-string">&#39;=&#39;</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>, <span class="ruby-value">:no_stream</span>)&#x000A;      <span class="ruby-keyword">end</span>&#x000A;    <span class="ruby-keyword">else</span>  <span class="ruby-comment"># plain procedure = method available to service class and its instance</span>&#x000A;      <span class="ruby-constant">Gen</span>.<span class="ruby-identifier">add_rpc_method</span>(<span class="ruby-identifier">service_class</span>, <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">service_name</span>, <span class="ruby-identifier">proc</span>, <span class="ruby-value">:static</span>)&#x000A;    <span class="ruby-keyword">end</span>&#x000A;  <span class="ruby-keyword">end</span>&#x000A;  &#x000A;  <span class="ruby-comment"># Return service class</span>&#x000A;  <span class="ruby-identifier">service_class</span>&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id='footer-push'></div>
    </div>
    <div id='footer'>
      <a target="docwin" href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
    </div>
  </body>
</html>
